# -*- coding: utf-8 -*-
from django import forms
from django.conf import settings
from main.models import Employee
import repairs
from repairs.models import RepairWorkers, Repair
from repairs.widgets import CalendarWidget

class R_CreateForm(forms.ModelForm):
    class Meta:
        model = Repair

    def __init__(self, *args, **kwargs):
        super(R_CreateForm, self).__init__(*args, **kwargs)
        self.fields['start'].widget = CalendarWidget()
        self.fields['end'].widget = CalendarWidget()

    def clean(self):
        cleaned_data = self.cleaned_data
        r_start = cleaned_data.get("start")
        r_end = cleaned_data.get("end")
        d = r_end-r_start

        if r_start > r_end:
            raise forms.ValidationError("Дата начала не может быть больше даты окончания.")
        if d.days > 10:
            raise forms.ValidationError("Слишком большая разница между началом и окончанием.")
        return cleaned_data